import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import './plugins/element.js'
import _ from 'lodash'
// import $axios from './http/request'
// Vue.prototype.$axios = $axios

import 'normalize.css'
// 公共样式
import '@/assets/css/public.css'
// 字体图标样式
import '@/assets/iconfont/iconfont.css'
Vue.config.productionTip = false
// 接口全局引入
import * as API from '@/http/api'
Vue.prototype.$API = API

//绘图
import echarts from 'echarts'

Vue.prototype.$echarts = echarts
//table树形表格
import TreeTable from 'vue-table-with-tree-grid'

Vue.config.productionTip = false

Vue.component('tree-table', TreeTable)


import VueQuillEditor from 'vue-quill-editor'

//引入vue-quill-editor富文本编辑器css样式
import 'quill/dist/quill.core.css' // import styles
import 'quill/dist/quill.snow.css' // for snow theme
import 'quill/dist/quill.bubble.css' // for bubble theme

//注册
Vue.use(VueQuillEditor)


// 
// router.beforeEach((to, from, next) => {
//   console.log(to)
//   if (to.path == '/login') {
//     next()
//     return
//   }

//   if (localStorage.getItem('token')) {
//     next()
//   } else {
//     next('/login')
//   }

// })
Vue.filter('dateFormat', function (originVal) {
  const dt = new Date(originVal)

  const y = dt.getFullYear()
  const m = (dt.getMonth() + 1 + '').padStart(2, '0')
  const d = (dt.getDate() + '').padStart(2, '0')

  const hh = (dt.getHours() + '').padStart(2, '0')
  const mm = (dt.getMinutes() + '').padStart(2, '0')
  const ss = (dt.getSeconds() + '').padStart(2, '0')

  return `${y}-${m}-${d} ${hh}:${mm}:${ss}`
})

router.beforeEach((to, from, next) => {
  if (to.path !== "/login") {

    let token = sessionStorage.getItem("token");

    if (token == null) {

      next("/login");
    }
  }

  next();
})


new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
